import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import functinn as f

txt_path = 'ex2data1.txt'
data = pd.read_csv(txt_path, names=['x1', 'x2', 'y'])

x, y, theta = f.get_xy(data)

alpha = 0.004
iteration = 200000
theta = f.gradientDescent(x=x, y=y, theta=theta, alpha=alpha, iteration=iteration)
print(theta)

para1 = - theta[0, 0] / theta[2, 0]
para2 = - theta[1, 0] / theta[2, 0]

fig, ax = plt.subplots(figsize=(7, 5))
a = np.linspace(20, 100, 2)
b = para1 + para2 * a
ax.plot(a, b, c='g', label='Decision Boundary')

ax.scatter(data[data['y'] == 0]['x1'], data[data['y'] == 0]['x2'], c='r', marker='x', label='y=0')
ax.scatter(data[data['y'] == 1]['x1'], data[data['y'] == 1]['x2'], c='b', marker='o', label='y=1')

ax.legend()
ax.set(xlabel='x1', ylabel='x2')
plt.show()
